package huy.mmt.gamelathinh;

import huy.mmt.gamelathinh.config.Config;
import huy.mmt.gamelathinh.dialog.DialogExit;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Main extends Activity implements OnClickListener {

	ImageButton play, setting, highscore, help;
	public static MediaPlayer click;

	ImageView moster_main;
	AnimationDrawable start_animation;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		moster_main = (ImageView) findViewById(R.id.monster_image);
		moster_main.setBackgroundResource(R.drawable.animation_start);
		start_animation = (AnimationDrawable) moster_main.getBackground();

		play = (ImageButton) findViewById(R.id.bt_play);
		play.setOnClickListener(this);

		setting = (ImageButton) findViewById(R.id.bt_setting);
		setting.setOnClickListener(this);

		highscore = (ImageButton) findViewById(R.id.bt_highscore);
		highscore.setOnClickListener(this);

		help = (ImageButton) findViewById(R.id.bt_help);
		help.setOnClickListener(this);
		// am thanh click nut

		click = MediaPlayer.create(this, R.raw.click);
		Config.getDisplayScreen(this);
	}

	// Animation
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			start_animation.start();
			return true;

		} else
			return super.onTouchEvent(event);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.bt_play:
			clickPlay();
			break;
		case R.id.bt_help:
			clickHelp();
			break;
		case R.id.bt_setting:
			clickSetting();
			break;

		case R.id.bt_highscore:
			clickHighscore();
			break;
		default:
			break;
		}
	}

	// .................................................

	public void clickPlay() {
		try {
			Intent intent = new Intent(this, Play.class);
			this.startActivity(intent);
			Main.click.start();
		} catch (Exception e) {
		}
	}

	// ------------------------------------------------------
	public void clickHelp() {
		try {
			Intent intent = new Intent(this, Help.class);
			this.startActivity(intent);
			Main.click.start();
		} catch (Exception e) {
		}
	}

	// ------------------------------------------------------
	public void clickExit() {
		try {
			DialogExit dialogExit = new DialogExit(this);
			dialogExit.show();
			Main.click.start();
		} catch (Exception e) {
		}
	}

	// ------------------------------------------------------
	public void clickSetting() {
		try {
			Intent intent = new Intent(this, Setting.class);
			this.startActivity(intent);
			Main.click.start();
		} catch (Exception e) {
		}
	}

	// ------------------------------------------------------
	public void clickHighscore() {
		try {
			Intent intent = new Intent(this, HighScore.class);
			this.startActivity(intent);
			Main.click.start();
		} catch (Exception e) {
		}
	}

	@Override
	public void onBackPressed() {
		Main.click.start();
		clickExit();

	}
}
